import { shallowReactive, type ShallowReactive } from "vue";
import {
    LayerConfig,
    LayerCreator,
    MapLayerInstances,
    MapLayer,
    GeoJsonLayerInstances,
    GeoJsonMapLayer
} from "./mapLayer";

export type RefMapLayer = ShallowReactive<MapLayer>;

/**
 * 创建响应式地图图层对象
 * @param config 地图图层配置
 * @param creator 地图图层创建器
 * @returns 响应式地图图层对象
 */
export function createRefMapLayer(
    config: LayerConfig,
    creator: LayerCreator<MapLayerInstances>
): RefMapLayer {
    return shallowReactive(new MapLayer(config, creator));
}

export type RefGeoJsonMapLayer = ShallowReactive<GeoJsonMapLayer>;

/**
 * 创建响应式 GeoJson 地图图层对象
 * @param config 地图图层配置
 * @param creator 地图图层创建器
 * @returns 响应式 GeoJson 地图图层对象
 */
export function createRefGeoJsonMapLayer(
    config: LayerConfig,
    creator: LayerCreator<GeoJsonLayerInstances>
): RefGeoJsonMapLayer {
    return shallowReactive(new GeoJsonMapLayer(config, creator));
}
